<template>
    <view class="container" v-if="showRegisterInfo" :style="themeColor">
        <view class="box">
            <view class="titletip">用户注册</view>
            <view class="h5-box">
                <view class="sub-item" v-if="showRegisterInfo.Company">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.Company.IsRequired == 1">*</text>{{
                            registerFrom.Company.ViewName }}</text>
                        <input class="value value-input" v-model="companyName"
                            :placeholder="'请输入' + registerFrom.Company.ViewName"
                            placeholder-class="input-placeholder" />
                    </view>
                </view>
                <view class="sub-item" @click="setdis" v-if="showRegisterInfo.Region">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.Region.IsRequired == 1">*</text>{{
                            registerFrom.Region.ViewName }}</text>
                        <text class="value" :class="disName == '' ? 'input-placeholder' : ''">{{
                            disName ? disName : "请选择所属" + registerFrom.Region.ViewName
                        }}</text>
                        <uni-icons class="icon-right" type="arrowright"></uni-icons>
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.Grade" @click="openPop">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.Grade.IsRequired == 1">*</text>{{
                            registerFrom.Grade.ViewName }}</text>
                        <text class="value" :class="selectGrade.Name == '' ? 'input-placeholder' : ''">{{
                            selectGrade.Name ? selectGrade.Name : registerGradeName
                        }}</text>
                        <uni-icons class="icon-right" type="arrowright"></uni-icons>
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.RealName">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.RealName.IsRequired == 1">*</text>{{
                            registerFrom.RealName.ViewName }}</text>
                        <input class="value value-input" v-model="realName"
                            :placeholder="'请输入' + registerFrom.RealName.ViewName"
                            placeholder-class="input-placeholder" />
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.Mobile">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.Mobile.IsRequired == 1">*</text>{{
                            registerFrom.Mobile.ViewName }}</text>
                        <input class="value value-input" :disabled="phoneShow" v-model="userName" maxlength="11"
                            type="number" :placeholder="'请输入' + registerFrom.Mobile.ViewName"
                            placeholder-class="input-placeholder" />
                    </view>
                </view>
                <view class="cell-item input-item" v-if="showRegisterInfo.SMSVerifyCode">
                    <text class="label"><text v-if="registerFrom.SMSVerifyCode.IsRequired == 1">*</text>{{
                        registerFrom.SMSVerifyCode.ViewName }}</text>
                    <input class="value value-input" v-model="validCode" maxlength="11" type="number"
                        :placeholder="'请输入' + registerFrom.SMSVerifyCode.ViewName"
                        placeholder-class="input-placeholder" />
                    <text @click="getSMSCode" style="color: #006eff">{{ sendText }}</text>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.PassWord">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.PassWord.IsRequired == 1">*</text>{{
                            registerFrom.PassWord.ViewName }}</text>
                        <input class="value value-input" type="password" v-model="password"
                            :placeholder="'请输入' + registerFrom.PassWord.ViewName"
                            placeholder-class="input-placeholder" />
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.Address">
                    <view class="cell-item" @click="areaSelectFn">
                        <text class="label"><text v-if="registerFrom.Address.IsRequired == 1">*</text>地区选择</text>
                        <text class="value" :class="regionName == '' ? 'input-placeholder' : ''">{{
                            regionName ? regionName : "请选择所在地区"
                        }}</text>
                        <uni-icons class="icon-right" type="arrowright"></uni-icons>
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.Address">
                    <view class="cell-item address-item">
                        <text class="label"><text v-if="registerFrom.Address.IsRequired == 1">*</text>{{
                            registerFrom.Address.ViewName }}</text>
                        <view class="dingwei">
                            <textarea class="value-textarea" v-model="address" placeholder="请先选择定位"
                                placeholder-class="input-placeholder"></textarea>
                            <view class="btn-location" @click="getLoaction">
                                <image src="/static/img/map.png"></image>
                                <iconsfont customIcons="icon-dizhi" color="#333333" size="30"></iconsfont>
                                <text>{{ data.Longitude ? "已定位" : "添加定位" }}</text>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="sub-item" v-if="showRegisterInfo.InvitUser">
                    <view class="cell-item input-item">
                        <text class="label"><text v-if="registerFrom.InvitUser.IsRequired == 1">*</text>{{
                            registerFrom.InvitUser.ViewName }}</text>
                        <input class="value value-input" type="number" maxlength="11" v-model="InvitUserTel"
                            :placeholder="'请输入' + registerFrom.InvitUser.ViewName + '手机号码'"
                            placeholder-class="input-placeholder" :disabled="!invitUserPhone" />
                    </view>
                </view>
            </view>
            <view class="agreement" v-if="getAppSet().agreement">
                <label class="agrlabel" @click="selectFn(agreementchecked)">
                    <iconsfont customIcons="icon-yuanquan" :color="$store.state.themeColor" size="32"
                        v-show="!agreementchecked"></iconsfont>
                    <iconsfont customIcons="icon-xuanzhong1" :color="$store.state.themeColor" size="32"
                        v-show="agreementchecked"></iconsfont>
                </label>
                <view class="color-dark" @click="selectFn(agreementchecked)">登录注册表示您已阅读并同意</view>
                <view><text @click="agreement()">《用户协议》</text>和<text @click="privacy()">《隐私政策》</text></view>
            </view>
            <button class="btn btn-success btn-save" @click="register">注册</button>
            <view :class="webInfo.IsVisitor && (!token || token == '') ? 'login-bottom' : 'login-bottom login-bottom-center'
                ">
                <view class="register-tip" @click="easyGoTo('/pages/login/index')">
                    <text>已有账号，立即</text><text class="link-text">登录</text>
                </view>
                <view class="tourist" v-if="webInfo.IsVisitor && (!token || token == '')" @click="touristFn">
                    <view class="yuan">
                        <iconsfont customIcons="icon-zuji" color="#fff" size="26"></iconsfont>
                    </view>游客登录
                </view>
            </view>
        </view>

        <!-- <image class="loginBg" :src="easyGetImgUrl(loginBg)" v-if="loginBg" mode="aspectFill"></image>
          -->
        <!-- #ifdef MP -->
        <web-view class="webView" v-if="isShow" ref="webView" :src="url">
            <cover-view class="webView-mark" v-if="showNav"> </cover-view>
        </web-view>
        <!-- #endif -->

        <uni-popup type="bottom" ref="gradeNamePop" background-color="#fff" :safe-area="false">
            <view class="pop-pay-way">
                <view class="title"><text>{{ registerGradeName }}</text></view>
                <scroll-view scroll-y="true" class="add-pay-way-scroll">
                    <view class="pay-way">
                        <view class="pay-way-item" v-for="(item, index) in memberList" @click="changeGrade(item)">
                            <text>{{ item.Name }}</text>
                        </view>
                    </view>
                </scroll-view>
                <button class="btn" @click="canceGrade">取消</button>
            </view>
        </uni-popup>
        <uni-popup type="bottom" ref="addresslist" background-color="#fff" :safe-area="false">
            <view class="pop-pay-way">
                <view class="title"><text>请选择所属{{ registerFrom.Region ? registerFrom.Region.ViewName : '公司' }}</text>
                </view>
                <scroll-view scroll-y="true" class="add-pay-way-scroll">
                    <view class="pay-way">
                        <view class="pay-way-item" v-for="(item, index) in dislist" @click="selectaddress(item, index)">
                            <text>{{ item.Name }}</text>
                        </view>
                    </view>
                </scroll-view>
                <button class="btn" @click="canceladdresslist">取消</button>
            </view>
        </uni-popup>
        <uni-popup ref="areaSelect" type="bottom" background-color="#fff" :safe-area="false">
            <area-select :address-data="data" @pickArea="pickArea"></area-select>
        </uni-popup>
        <uni-popup ref="popReturnTip" type="center" :animation="false" :is-mask-click="false">
            <view class="pop-return-box">
                <view class="pop-return-title">
                    <text>提示</text>
                </view>
                <view class="pop-tip">该手机号已关联用户</view>
                <view class="pop-action">
                    <view @click="againRegister">注册新用户</view>
                    <view @click="loginGo">直接登录</view>
                </view>
            </view>
        </uni-popup>
        <privacy-agreement></privacy-agreement>

        <!-- 前往下载app -->
        <uni-popup ref="downloadTip" type="center" :animation="false" :maskClick="true">
            <view class="download-tip">
                <view class="tip">您已提交注册申请</view>
                <button class="btn btn-success" @click="downloadApp">前往下载APP</button>
            </view>
        </uni-popup>
    </view>
</template>

<script>
import { mapMutations, mapState } from "vuex"
import areaSelect from "@/uni-sub-base/components/area-select/area-select.vue"
import cardCellInput from "@/components/common/cell/card-cell-input.vue"
import storage from "@/uni-sub-base/utils/storage.js"
import config from "@/config/config.js"
import { getUserInfo, getProductDisplay, getInitWebInfo } from "@/utils/appInit.js"
import { getUserCarList } from "@/utils/cartUtil.js"
import privacyAgreement from "@/components/privacy-agreement/privacy-agreement.vue"
import { getDomain, getBusinessld } from "@/utils/appUrls.js"

import {
    getMemberDetail,
    judgeIsExist,
    batchSmartParse,
    UserLogin,
    SendSmsNoVerifyCode,
    GetDisList,
    GetMemberGradeInfo
} from "@/service/api/member.js"
import { SubmitRegister } from "@/service/api/authorize.js"
import { GetRegisterInitData, getSmsNoVerifyCode } from "@/service/api/web.js"
import webViewUrl from "@/pages/micro/webViewUrl.js"
import { getPlatform } from "@/uni-sub-base/utils/platformUtil.js"
import { getLocation } from "@/uni-sub-base/utils/mapUtil.js"
import { mapbatchSmartParse } from "@/service/api/user.js"
export default {
    components: {
        cardCellInput,
        areaSelect,
        privacyAgreement
    },
    data() {
        return {
            // config: {
            //     back: false,
            //     barPlaceholder: false,
            //     backgroundColor: [0, "#ffffff"],
            // },
            companyName: "",
            disName: "",
            disId: 0,
            realName: "",
            userName: "",
            validCode: "",
            password: "",
            regionName: "",
            address: "",
            InvitUserTel: "",
            logo: "",
            loginBg: "",
            isShow: false,
            url: "",
            showNav: false,
            selectShopName: "",
            registerInfo: {},
            showRegisterInfo: null,
            memberList: [],
            registerGradeName: "",
            InvitUserPlaceholde: "请填写邀请人编号",
            selectGrade: {
                Name: "",
            },
            sendText: "获取验证码",
            sendAble: true,
            registerFrom: null,
            data: {
                AddressName: "",
                ContactName: "",
                ContactTel: "",
                ContactAddress: "",
                IsDefault: false,
                ProvinceId: 0,
                ProvinceName: "",
                CityId: 0,
                CityName: "",
                AreaId: 0,
                AreaName: "",
                StreetId: 0,
                StreetName: "",
                Longitude: "",
                Latitude: "",
                ZipCode: null,
            },
            verCode: "",
            agreementchecked: false,
            dislist: [],
            phone: "",
            phoneShow: false,
            subOne: true,
            submitData: {},
            token: "",
            webInfo: {},
            isScanCodeEnter: false, // 
            registerTip: "",
            invitUserPhone: "",
        }
    },
    onLoad(e) {
        if (e.phone) {
            this.phone = e.phone
            this.phoneShow = true
            this.userName = e.phone
        }
        if (e.isScanCodeEnter) {
            this.isScanCodeEnter = true
        }
        if (e.invitUserPhone) {
            this.InvitUserTel = e.invitUserPhone
        }
    },
    mounted() {
        this.getWebInfo()
        this.getRegisterInitData()
        this.GetDisList()
        this.token = storage.getCache("token")
        this.webInfo = storage.getCache("webInfo")
    },
    methods: {
        ...mapMutations(["SET_AUTH"]),
        GetDisList() {
            GetDisList().then((res) => {
                if (res.State == 1) {
                    this.dislist = res.Data
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        loginByService() {
            let password = this.userName.substring(this.userName.length - 6, this.userName.length)
            let param = {
                userName: this.userName,
                password: this.password ? this.password : password,
            }
            let path = "?userName=" + this.userName + "&password=" + this.password
            UserLogin(param).then((res) => {
                if (res.State == 1) {
                    if (res.Data.State == 0) {
                        let token = res.Data.Token
                        this.goHome(token)
                    } else if (res.Data.State == 1) {
                        uni.hideLoading()
                        this.easyToast("您已提交注册申请，等待审核中")
                    } else {
                        uni.hideLoading()
                        this.easyToast(res.Data.StateName)
                    }
                } else {
                    uni.hideLoading()
                    this.easyToast(res.Msg)
                }
            })
        },
        selectFn(vaule) {
            this.agreementchecked = !this.agreementchecked
        },
        agreement() {
            // this.easyGoTo("/pages/web/h5?url=" + encodeURIComponent(this.getAppSet().agreementUrl))
            this.easyGoTo("/pages/web/agreement?type=4")
        },
        privacy() {
            // this.easyGoTo("/pages/web/h5?url=" + encodeURIComponent(this.getAppSet().privacyUrl))
            this.easyGoTo("/pages/web/agreement?type=5")
        },
        showLoginLoadding() {
            uni.showLoading({
                title: "注册中",
            })
        },
        changeImg() { },
        changeGrade(item) {
            this.selectGrade = item
            this.close()
        },
        close() {
            this.$refs.gradeNamePop.close()
        },
        openPop() {
            this.$refs.gradeNamePop.open()
        },
        goHome(token) {
            this.SET_AUTH(token)

            //#ifdef APP-PLUS
            if (getPlatform() == "ios") {
                let webInfo = storage.getCache("webInfo")
                if (webInfo) {
                    this.url =
                        webInfo.WebDomain +
                        (webInfo.AppHomeIndex ? webInfo.AppHomeIndex : webViewUrl.url.home) +
                        "?uniToken=" +
                        token
                }
                this.isShow = false
                setTimeout((e) => {
                    this.getUserInfo()
                }, 2500)
                getUserCarList()
                getProductDisplay().then((res) => { })
            } else {
                this.getUserInfo()
                getUserCarList()
                getProductDisplay().then((res) => { })
            }
            //#endif
            //#ifndef APP-PLUS
            let webInfo = storage.getCache("webInfo")
            if (webInfo) {
                this.url =
                    webInfo.WebDomain +
                    (webInfo.AppHomeIndex ? webInfo.AppHomeIndex : webViewUrl.url.home) +
                    "?uniToken=" +
                    token
            }
            this.isShow = false
            setTimeout((e) => {
                this.getUserInfo()
            }, 2500)
            getUserCarList()
            getProductDisplay().then((res) => { })
            //#endif
        },
        getUserInfo() {
            let url = "/pages/index/index"
            getUserInfo().then((res) => {
                uni.hideLoading()
                uni.reLaunch({
                    url: url,
                })
            })
        },
        saveUserInfo(data) {
            storage.setCache("userInfo", data)
        },
        selectaddress(item, index) {
            this.disName = item.Name
            this.disId = item.ID
            this.$refs.addresslist.close()
        },
        //获取手机短信验证码需要图片验证码
        // getSMSCode() {
        // 	let userName = this.$refs.userName.getValue()
        // 	let password = this.$refs.password.getValue()
        // 	let ImageVerifyCode = this.$refs.ImageVerifyCode.getValue()
        // 	if (!userName) {
        // 		this.easyToast("请输入手机号")
        // 		return false
        // 	}
        // 	if (!password) {
        // 		this.easyToast("请输入密码")
        // 		return false
        // 	}
        // 	if (!ImageVerifyCode && this.registerInfo.ImageVerifyCode == 1) {
        // 		this.easyToast("请输入图形验证码")
        // 		return false
        // 	}
        // 	if (ImageVerifyCode != this.verCode && this.registerInfo.ImageVerifyCode == 1) {
        // 		this.easyToast("请输入正确的图形验证码")
        // 		return false
        // 	}
        // 	this.sendText = "正在发送中..."
        // 	this.sendAble = false
        // 	let param = {
        // 		tel:userName,
        // 		imgCode:ImageVerifyCode,
        // 		validType:8,
        // 	}
        // 	let path = "?tel="+userName+ "&imgCode=" + ImageVerifyCode + "&validType=8"
        // 	getSmsNoVerifyCode(param,path).then(res => {
        // 		if (res.State) {
        // 			this.easyToast("验证码已发送，请查收")
        // 			storage.setCache("LastSendSmsTime", new Date()); //保存上次发送时间
        // 			this.setTimer()
        // 		} else {
        // 			this.sendText = "获取验证码"
        // 			this.sendAble = true
        // 			this.easyToast(res.Msg)
        // 		}
        // 	})
        // },
        getSMSCode() {
            if (this.userName == "") {
                this.easyToast("请输入手机号码")
                return false
            }
            this.sendText = "正在发送中..."
            this.sendAble = false
            let path = "?tel=" + this.userName + "&validType=8"
            SendSmsNoVerifyCode(path).then((res) => {
                if (res.State) {
                    this.easyToast("验证码已发送，请查收")
                    storage.setCache("LastSendSmsTime", new Date()) //保存上次发送时间
                    this.setTimer()
                } else {
                    this.sendText = "获取验证码"
                    this.sendAble = true
                    this.easyToast(res.Msg)
                }
            })
        },

        setTimer() {
            const that = this
            let lastTime = this.getRemainSec()
            if (lastTime > 0) {
                clearInterval(that.timer)
                that.timer = setInterval(function () {
                    if (lastTime > 0) {
                        that.sendAble = false
                        that.sendText = "重新发送(" + lastTime + "s)"
                    } else {
                        that.sendAble = true
                        that.sendText = "重新发送"
                        clearInterval(that.timer)
                    }
                    lastTime--
                }, 1000)
            } else {
                storage.removeCache("LastSendSmsTime")
            }
        },
        getRemainSec() {
            let lastTime = storage.getCache("LastSendSmsTime")
            if (lastTime) {
                try {
                    let time = 60 - Math.ceil((new Date() - new Date(lastTime)) / 1000)
                    return time > 0 ? time : 0
                } catch (e) { }
            }
            return 0
        },
        register() {
            if (this.subOne) {
                let InvitUser = 0,
                    RealName = "",
                    GradeId = this.selectGrade.ID || 0
                if (this.registerFrom.Company && this.registerFrom.Company.IsRequired == 1 && this.companyName == "") {
                    this.easyToast('请输入' + this.registerFrom.Company.ViewName)
                    return false
                }
                if (this.registerFrom.Region && this.registerFrom.Region.IsRequired == 1 && this.disName == "") {
                    this.easyToast("请选择所属" + this.registerFrom.Region.ViewName)
                    return false
                }
                if (this.registerFrom.Grade && this.registerFrom.Grade.IsRequired == 1 && this.selectGrade.Name == "") {
                    this.easyToast("请选择会员等级")
                    return false
                }
                if (this.registerFrom.RealName && this.registerFrom.RealName.IsRequired == 1 && this.realName == "") {
                    this.easyToast("请输入" + this.registerFrom.RealName.ViewName)
                    return false
                }
                if (this.registerFrom.Mobile && this.registerFrom.Mobile.IsRequired == 1 && this.userName == "") {
                    this.easyToast("请输入" + this.registerFrom.Mobile.ViewName)
                    return false
                }
                if (this.registerFrom.Mobile && this.registerFrom.Mobile.IsRequired == 1 && this.userName) {
                    let regMobile = /^1[3456789]\d{9}$/
                    if (!regMobile.test(this.userName)) {
                        this.easyToast("请输入正确的手机号")
                        return false
                    }
                }
                if (
                    this.registerFrom.SMSVerifyCode &&
                    this.registerFrom.SMSVerifyCode.IsRequired == 1 &&
                    this.validCode == ""
                ) {
                    this.easyToast("请输入短信验证码")
                    return false
                }
                if (this.registerFrom.PassWord && this.registerFrom.PassWord.IsRequired == 1 && this.password == "") {
                    this.easyToast("请输入" + this.registerFrom.PassWord.ViewName)
                    return false
                }
                if (this.registerFrom.Address && this.registerFrom.Address.IsRequired == 1 && this.regionName == "") {
                    this.easyToast("请选择所在地区")
                    return false
                }
                if (this.registerFrom.Address && this.registerFrom.Address.IsRequired == 1 && this.address == "") {
                    this.easyToast("请定位地址")
                    return false
                }
                if (this.registerFrom.Address && this.registerFrom.Address.IsRequired == 1) {
                    if (!this.data.Longitude || !this.data.Latitude) {
                        this.easyToast("请定位地址")
                        return
                    }
                }
                if (
                    this.registerFrom.InvitUser &&
                    this.registerFrom.InvitUser.IsRequired == 1 &&
                    this.InvitUserTel == ""
                ) {
                    this.easyToast("请输入" + this.registerFrom.InvitUser.ViewName)
                    return false
                }
                if (!this.agreementchecked && this.getAppSet().agreement == true) {
                    this.easyToast("请先同意《用户协议》和《隐私政策》")
                    return
                }
                let inviteTel = storage.getCache("inviteTel")
                let param = {
                    CompanyName: this.companyName,
                    GradeId: GradeId,
                    disId: this.disId,
                    InvitUserTel: this.InvitUserTel ? this.InvitUserTel : inviteTel,
                    UserName: this.userName,
                    UserPsw: this.password,
                    validType: 8,
                    validCode: this.validCode,
                    provinceId: this.data.ProvinceId,
                    cityId: this.data.CityId,
                    regionId: this.data.AreaId,
                    streetId: this.data.StreetId,
                    provinceName: this.data.ProvinceName,
                    cityName: this.data.CityName,
                    regionName: this.data.AreaName,
                    streetName: this.data.StreetName,
                    address: this.address,
                    lat: this.data.Latitude ? this.data.Latitude : 0,
                    lng: this.data.Longitude ? this.data.Longitude : 0,
                    realName: this.realName,
                    DataIntegrityFlag: 1,
                }
                if (this.userName == "") {
                    this.easyToast("请输入手机号")
                    return false
                }
                if (this.userName) {
                    let regMobile = /^1[3456789]\d{9}$/
                    if (!regMobile.test(this.userName)) {
                        this.easyToast("请输入正确的手机号")
                        return false
                    }
                }
                this.subOne = false
                judgeIsExist(this.userName).then((res) => {
                    if (res.State == 1) {
                        this.showLoginLoadding()
                        SubmitRegister(param).then((data) => {
                            if (data.State == 1) {
                                storage.removeCache("inviteTel")
                                if (data.Data.State == 0) {
                                    if (this.isScanCodeEnter) {
                                        this.registerTip = "注册成功"
                                        uni.hideLoading()
                                        this.$refs.downloadTip.open()
                                    } else {
                                        this.easyToast("注册成功")
                                        setTimeout((e) => {
                                            //接登录
                                            this.loginByService()
                                        }, 800)
                                    }
                                } else if (data.Data.State == 1) {
                                    if (this.isScanCodeEnter) {
                                        this.registerTip = "您已提交注册申请"
                                        uni.hideLoading()
                                        this.$refs.downloadTip.open()
                                    } else {
                                        this.easyToast("您已提交注册申请")
                                        setTimeout((e) => {
                                            this.easyGoBack()
                                        }, 1500)
                                    }
                                } else if (data.Data.State == 5) {
                                    if (this.isScanCodeEnter) {
                                        this.registerTip = "您当前所在的区域未开放，请等待审核"
                                        uni.hideLoading()
                                        this.$refs.downloadTip.open()
                                    } else {
                                        this.easyToast("您当前所在的区域未开放，请等待审核")
                                        setTimeout((e) => {
                                            this.easyGoBack()
                                        }, 1500)
                                    }
                                }
                                setTimeout((e) => {
                                    this.subOne = true
                                }, 2500)
                            } else {
                                uni.hideLoading()
                                this.easyToast(data.Msg)
                                setTimeout((e) => {
                                    this.subOne = true
                                }, 2000)
                            }
                        })
                    } else {
                        if (res.Msg != "用户已存在") {
                            this.easyToast(res.Msg)
                            if (this.isScanCodeEnter) {
                                this.registerTip = res.Msg
                                uni.hideLoading()
                                this.$refs.downloadTip.open()
                            }
                            let webInfo = storage.getCache("webInfo")
                            if (res.Msg == "用户已存在" && webInfo.OneTelLoginMoreUser == 1) {
                                this.submitData = param
                                this.$refs.popReturnTip.open()
                            } else {
                                this.easyToast(res.Msg)
                                if (this.isScanCodeEnter) {
                                    this.registerTip = res.Msg
                                    uni.hideLoading()
                                    this.$refs.downloadTip.open()
                                }
                            }
                            setTimeout((e) => {
                                this.subOne = true
                            }, 2000)
                        }
                    }
                })
            }
        },
        loginGo() {
            this.$refs.popReturnTip.close()
            this.easyReLaunch("/pages/login/index")
        },
        againRegister() {
            this.$refs.popReturnTip.close()
            SubmitRegister(this.submitData).then((data) => {
                if (data.State == 1) {
                    if (data.Data.State == 0) {
                        if (this.isScanCodeEnter) {
                            this.registerTip = "注册成功"
                            uni.hideLoading()
                            this.$refs.downloadTip.open()
                        } else {
                            this.easyToast("注册成功")
                            //接登录
                            this.loginByService()
                        }
                    } else if (data.Data.State == 1) {
                        if (this.isScanCodeEnter) {
                            this.registerTip = "您已提交注册申请"
                            uni.hideLoading()
                            this.$refs.downloadTip.open()
                        } else {
                            this.easyToast("您已提交注册申请")
                            setTimeout((e) => {
                                this.easyGoBack()
                            }, 1500)
                        }
                    } else if (data.Data.State == 5) {
                        if (this.isScanCodeEnter) {
                            this.registerTip = "您当前所在的区域未开放，请等待审核"
                            uni.hideLoading()
                            this.$refs.downloadTip.open()
                        } else {
                            this.easyToast("您当前所在的区域未开放，请等待审核")
                            setTimeout((e) => {
                                this.easyGoBack()
                            }, 1500)
                        }
                    }
                } else {
                    uni.hideLoading()
                    this.easyToast(data.Msg)
                }
            })
        },
        saveUserInfo(data) {
            storage.setCache("userInfo", data)
        },
        getWebInfo() {
            let webInfo = storage.getCache("webInfo")
            if (webInfo) {
                this.logo = webInfo.Logo
                this.loginBg = webInfo.LoginBackgroud
            }
        },
        disable(userName, password) {
            return userName.trim() == "" || password.trim() == ""
        },
        //设置主题色
        setThemeColorFn(Style) {
            //主题色
            let themeColor = ""
            switch (Style) {
                case "green":
                    themeColor = "#2cd334"
                    break
                case "blue":
                    themeColor = "#4076fc"
                    break
                case "purple":
                    themeColor = "#ff547c"
                    break
                case "black":
                    themeColor = "#000000"
                    break
                case "lightOrange":
                    themeColor = "#feae58"
                    break
                case "red":
                    themeColor = "#eb1010"
                    break
                case "rose":
                    themeColor = "#725abe"
                    break
                case "gyellow":
                    themeColor = "#dba868"
                    break
                case "orange":
                    themeColor = "#fe5822"
                    break
                case "blackBlue":
                    themeColor = "#2c4068"
                    break
                case "zise":
                    themeColor = "#fdbc00"
                    break
                case "style12":
                    themeColor = "#f6b7bc"
                    break
                case "style13":
                    themeColor = "#2a7472"
                    break
                case "weixing":
                    themeColor = "#0ab483"
                    break
                default:
                    themeColor = this.easyGetColor("main")
                    break
            }
            storage.setCache("themeColor", themeColor)
            this.SET_THEME_COLOR(themeColor)
        },
        async getRegisterInitData() {
            console.log('getRegisterInitData')
            if (this.isScanCodeEnter) {
                await this.GetGuideApi()//接口获取API地址
            }
            await this.GetGuideApi()//接口获取API地址

            let domain = getDomain()
            let Businessld = getBusinessld()
            console.log(domain)
            console.log(Businessld)

            console.log('getRegisterInitData开始')
            GetRegisterInitData().then((res) => {
                if (res.State == 1) {
                    this.memberList = res.Data.MemberGradeList
                    this.registerGradeName = "请选择" + res.Data.RegisterGradeName
                    if (res.Data.Infos && res.Data.Infos.length > 0) {
                        this.showRegisterInfo = {}
                        this.registerFrom = {}
                        res.Data.Infos.forEach((item) => {
                            this.showRegisterInfo[item.V_ItemParam] = item.IsDisplay
                            this.registerInfo[item.V_ItemParam] = item.IsRequired
                            this.registerFrom[item.V_ItemParam] = {
                                IsDisplay: item.IsDisplay,
                                IsRequired: item.IsRequired,
                                ViewName: item.ViewName
                            }
                        })
                    } else {
                        this.easyToast("后台未设置注册项")
                    }
                    if (!this.registerInfo.InvitUser || this.registerInfo.InvitUser == 0) {
                        this.InvitUserPlaceholde = "请输入邀请人编号(选填)"
                    }
                }
            })
        },
        //选择地区
        areaSelectFn() {
            this.$refs.areaSelect.open()
        },
        //选择地区回调
        pickArea(data) {
            this.$refs.areaSelect.close()
            this.data = Object.assign(this.data, data)
            this.getRegionName()
        },
        getRegionName() {
            let line = "-"
            this.regionName = `${this.data.ProvinceName || ""}-${this.data.CityName || ""}${this.data.AreaName ? line + this.data.AreaName : ""
                }${this.data.StreetName ? line + this.data.StreetName : ""}`
            // this.data.ProvinceName?this.data.ProvinceName:'' +
            // this.data.CityName?"-"+this.data.CityName:''+
            // this.data.AreaName?"-"+this.data.AreaName:''+
            // this.data.StreetName?"-"+this.data.StreetName:''
        },
        getLoaction() {
            //#ifdef MP-WEIXIN
            this.getCenterLocation()
            //#endif
            //#ifdef APP
            let that = this
            uni.chooseLocation({
                success: function (res) {
                    console.log("位置名称：" + res.name)
                    console.log("详细地址：" + res.address)
                    console.log("纬度：" + res.latitude)
                    console.log("经度：" + res.longitude)
                    that.getAppP(res)
                    that.data.ContactAddress = res.name
                    that.data.Longitude = res.longitude
                    that.data.Latitude = res.latitude
                },
            })
            //#endif
            //#ifdef H5
            getLocation(
                (res) => {
                    if (res) {
                        this.data.ContactAddress = res.address.street + res.address.streetNum

                        this.getP(res.address)
                    }
                },
                (err) => {
                    console.log(err)
                },
            )
            //#endif
        },
        getCenterLocation() {
            var that = this
            wx.authorize({
                scope: "scope.userLocation",
                complete: function (res) {
                    wx.chooseLocation({
                        success(str) {
                            var getAddressUrl = 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=' + str.longitude + ',' + str.latitude +
                                "&key=" + config.aMapKey.wx
                            wx.request({
                                url: getAddressUrl,
                                success: function (result) {
                                    var province = result.data.regeocode.addressComponent.province
                                    var city = result.data.regeocode.addressComponent.city
                                    var district = result.data.regeocode.addressComponent.district
                                    var address = result.data.regeocode.addressComponent.township + result.data.regeocode.addressComponent.streetNumber.street + result.data.regeocode.addressComponent.streetNumber.number

                                    // that.data.ContactAddress =province+city+district+address
                                    that.data.Longitude = str.longitude
                                    that.data.Latitude = str.latitude
                                    that.getmapP(
                                        result.data.regeocode.addressComponent,
                                        address
                                    )
                                },
                            })
                        },
                        fail(err) {
                            console.log(err)
                        }
                    })
                },
                fail(err) {
                    console.log(err)
                }
            })
        },
        getP(res) {
            let item = {
                ContactAddress: res.street + res.streetNum,
                ProvinceName: res.province,
                CityName: res.city,
                AreaName: res.district,
                StreeName: res.street,
                ContactName: this.data.ContactName || "aaa",
                ContactTel: this.data.ContactTel || "13300000000",
            }
            let list = []
            list.push(item)
            let param = {
                list: list,
            }
            this.batchSmartParse(param)
        },
        getAppP(res) {
            let item = {
                ContactAddress: res.address,
                ContactName: "aaa",
                ContactTel: "13300000000",
            }
            let list = []
            list.push(item)
            let param = {
                list: list,
            }
            this.batchSmartParse(param)
        },
        getmapP(res, address) {
            let item = {
                ContactAddress: address,
                ProvinceName: res.province,
                CityName: res.city,
                AreaName: res.district,
                StreetName: res.township,
                ContactName: this.data.ContactName || "aaa",
                ContactTel: this.data.ContactTel || "13300000000",
            }
            let list = []
            list.push(item)
            let param = {
                list: list,
            }
            this.batchSmartParse(param)
        },
        //智能识别
        batchSmartParse(param) {
            batchSmartParse(param).then((res) => {
                if (res.Data && res.Data.list && res.Data.list.length > 0) {
                    let result = res.Data.list[0]
                    this.data.ProvinceId = result.ProvinceId
                    this.data.ProvinceName = result.ProvinceName
                    this.data.CityId = result.CityId
                    this.data.CityName = result.CityName
                    this.data.AreaId = result.AreaId
                    this.data.AreaName = result.AreaName
                    this.data.StreetId = result.StreetId
                    this.data.StreetName = result.StreetName
                    this.address = result.ContactAddress
                    this.getRegionName()
                }
            })
        },
        changeCode(e) {
            this.verCode = e
        },
        setdis() {
            this.$refs.addresslist.open()
        },
        canceladdresslist() {
            this.$refs.addresslist.close()
        },
        canceGrade() {
            this.$refs.gradeNamePop.close()
        },
        touristFn() {
            let token = storage.getCache("token")
            let webInfo = storage.getCache("webInfo")
            if (webInfo.IsVisitor && (!token || token == "")) {
                //有游客账号
                uni.reLaunch({
                    url: "/pages/index/index",
                })
            } else {
                this.easyToast("后台未开启游客模式")
            }
        },
        downloadApp() {
            //#ifdef APP-PLUS
            plus.runtime.openURL('https://zcshop.zcbz.vip/AppApi/AppInstall?ApplicationId=com.zcbz.mangguo');
            // #endif

            //#ifdef MP
            wx.navigateTo({
                url: "https://zcshop.zcbz.vip/AppApi/AppInstall?ApplicationId=com.zcbz.mangguo"
            })
            //#endif

            //#ifdef 
            window.location.href = "https://zcshop.zcbz.vip/AppApi/AppInstall?ApplicationId=com.zcbz.mangguo"
            //#endif
        }
    },
}
</script>

<style lang="scss">
.container {
    padding: 50rpx 0 60rpx 0;
}

.btn-save {
    height: 88rpx;
    font-size: $font-size-36;
    width: 630rpx;
}

.add-pay-way-scroll {
    max-height: 50vh;

    .pay-way-item {
        justify-content: center;
        border-bottom: 1rpx solid #ebebeb;
    }
}

.logo {
    display: flex;
    justify-content: center;
    height: 100rpx;
    margin-bottom: 10rpx;

    .logo-img {
        width: 100rpx;
        height: 100rpx;
        border-radius: $border-radius-10;
        box-shadow: 0rpx 0rpx 30rpx rgba($color-black, 0.1);
    }
}

.h5-box {
    background: #fff;
    border-radius: 24rpx;

    .link-box {
        display: flex;
        flex-direction: row;
        height: 60rpx;
        justify-items: center;

        .change-type {
            display: flex;
            flex: 1;
            color: $app-color-text-tip;
        }

        .forget-pwd {
            display: flex;
            flex: 1;
            justify-content: flex-end;
            color: $app-color-text-tip;
        }
    }
}

.register-tip {
    display: flex;
    justify-content: center;

    .link-text {
        color: $app-color-main;
    }
}

.box {}

.loginBg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    let: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
}

.card-group {
    border-radius: 20rpx;

    .card-group-cell {
        padding-top: 20rpx;
        padding-bottom: 20rpx;

        &:last-child {
            border-bottom: none;
        }
    }
}

.region {
    padding: 0 20rpx;

    .cell-textarea {
        height: 100rpx;
        color: #323232;
        font-size: $font-size-28;
        margin-bottom: 14rpx;
    }

    .region-header {
        height: 100rpx;
        display: flex;
        flex-direction: row;
        align-items: center;

        .region-title {
            flex: 1;
        }
    }

    .region-info-text {
        display: flex;
        font-size: $font-size-28;
        margin-bottom: 14rpx;
    }
}

.disable {
    opacity: 0.5;
    border: none;
}

.webView-mark {
    width: 100vw;
    height: 100vh;
    background: #fff;
    position: fixed;
    z-index: 999999999999;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
}

.shop-name {
    display: flex;
    font-size: $font-size-40;
    margin-bottom: 40rpx;
    justify-content: center;
}

.noMt {
    margin-top: 0;
}

.bottom-list-box {
    background: $color-white;
    text-align: center;
    border-radius: 20rpx 20rpx 0 0;
    overflow: auto;

    .list-box {
        max-height: 700rpx;
        overflow-y: auto;

        .item {
            padding: 30rpx 0;
            margin: 0 30rpx;

            &:not(:last-child) {
                border-bottom: 2rpx solid $uni-border-color;
            }

            .pay-img {
                width: 60rpx;
                height: 60rpx;
                margin-right: 30rpx;
            }

            .item-text {
                font-size: 28rpx;

                .balance {
                    font-size: 24rpx;
                    color: $color-gray-3;
                    margin-left: 20rpx;
                }
            }
        }
    }

    .button {
        margin: 60rpx 40rpx;
        font-size: 36rpx;
        line-height: 88rpx;
        letter-spacing: 8rpx;
        background: $color-main;
        border-radius: 12rpx;
        color: $color-white;
    }
}

.agreement {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 40rpx 0rpx 24rpx 0rpx;

    .circle {
        width: 28rpx;
        height: 28rpx;
        border-radius: 50%;
        border: 1rpx solid #999;
        display: block;
        overflow: hidden;
    }

    .agrlabel {
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    view {
        font-size: 24rpx;

        text {
            color: $app-color-main !important;
        }
    }

    .color-dark {
        padding-left: 8rpx;
    }
}

.titletip {
    padding: 110rpx 0 38rpx 32rpx;
    font-size: 48rpx;
    color: #333333;
}

.sub-item:last-child {
    &>.cell-item {
        border-bottom: none;
    }
}

.cell-item {
    height: 112rpx;
    padding: 0 $app-page-padding;
    border-bottom: solid 1rpx #ebebeb;
    display: flex;
    flex-direction: row;
    align-items: center;

    .label {
        font-size: $font-size-32;
        color: $color-gray-1;
        width: 180rpx;
        display: block;

        text {
            color: #f93837;
        }
    }

    .value {
        flex: 1;
        display: flex;
        justify-content: space-between;
        font-size: $font-size-30;
        color: #323232;
    }

    .icon-right {
        margin-right: -8rpx;
    }
}

.input-placeholder {
    font-size: $font-size-32 !important;
    color: #bcbfcc !important;
}

.dingwei {
    background: #f6f7f7;
    border-radius: 8rpx;
    padding: 24rpx;
    width: calc(100% - 48rpx);
    flex: 1;
}

.address-item {
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: $app-page-padding;

    .label {
        margin-bottom: 10rpx;
    }

    .btn-location {
        flex: 1;
        display: flex;
        align-items: center;
        border-radius: 100rpx;
        justify-content: flex-end;
        color: #333333;
        margin-top: 30rpx;

        image {
            width: 24rpx;
            height: 24rpx;
            margin-right: 8rpx;
        }
    }

    .value-textarea {
        width: 100%;
        height: 86rpx;
        margin-bottom: 10rpx;
    }
}

.login-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 40rpx;
    padding: 0rpx 60rpx;

    .tourist {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        color: #999;

        .yuan {
            width: 38rpx;
            height: 38rpx;
            background: #fdb52a;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 20rpx;
            margin-right: 16rpx;
        }
    }
}

.login-bottom-center {
    justify-content: center;
}

.pop-return-box {
    background: $color-white;
    border-radius: $border-radius-10;
    padding: $app-page-padding;
    width: 600rpx;

    .pop-tip {
        text-align: center;
        padding: 60rpx 0;
        font-size: 32rpx;
        color: #999;
    }

    .pop-return-title {
        display: flex;
        justify-content: center;

        text {
            font-weight: 700;
            font-size: 34rpx;
        }
    }

    .pop-action {
        border-top: 1rpx solid rgba(0, 0, 0, 0.1);
        margin: 0 -24rpx -24rpx -24rpx;
        height: 110rpx;
        display: flex;
        align-items: center;
        justify-content: center;

        view {
            width: 50%;
            text-align: center;
            height: 110rpx;
            line-height: 110rpx;
            font-size: 34rpx;
            font-weight: bold;
            color: $app-color-main;
        }

        &>view:first-child {
            color: $color-gray-1;
            border-right: 1rpx solid rgba(0, 0, 0, 0.1);
        }
    }

    .return-msg {
        margin-bottom: 20rpx;

        .card-group-cell {
            margin-left: 0 !important;
        }
    }

    .img-title {
        display: flex;
        color: $app-color-text-tip;
        margin-bottom: 20rpx;
    }

    .action {
        display: flex;
        flex-direction: row;

        .btn {
            flex: 1;
            border-radius: $border-radius-10;
            height: 70rpx;

            &:first-child {
                margin-left: 0;
            }
        }
    }
}

.download-tip {
    width: 600rpx;
    margin-top: -50%;
    background: $color-white;
    border-radius: $border-radius-10;
    padding: 60rpx 30px;
    box-sizing: border-box;

    .tip {
        font-size: 28rpx;
        text-align: center;
        margin-bottom: 40rpx;
    }
}
</style>
